﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HappyTemplate.BuiltInFunctions
{
	public class ArgumentCollection
	{
		private readonly List<object> _list;
		internal ArgumentCollection(int capacity)
		{
			_list = new List<object>(capacity);
		}

		internal void Add(object arg)
		{
			_list.Add(arg);
		}

		public int Count { get { return _list.Count; } }

		public int GetInt32(int index)
		{
			try
			{
				return Convert.ToInt32(_list[index]);
			}
			catch(Exception e)
			{
				throw new ArgumentConversionException(index, e);
			}
		}

		public string GetString(int index)
		{
			try
			{
				return Convert.ToString(_list[index]);
			}
			catch (Exception e)
			{
				throw new ArgumentConversionException(index, e);
			}
		}

		public double GetDouble(int index)
		{
			try
			{
				return Convert.ToDouble(_list[index]);
			}
			catch (Exception e)
			{
				throw new ArgumentConversionException(index, e);
			}
		}

		public float GetSingle(int index)
		{
			try
			{
				return Convert.ToSingle(_list[index]);
			}
			catch (Exception e)
			{
				throw new ArgumentConversionException(index, e);
			}
		}

		public DateTime GetDateTime(int index)
		{
			try
			{
				return Convert.ToDateTime(_list[index]);
			}
			catch (Exception e)
			{
				throw new ArgumentConversionException(index, e);
			}
		}

		public bool GetBoolean(int index)
		{
			try
			{
				return Convert.ToBoolean(_list[index]);
			}
			catch (Exception e)
			{
				throw new ArgumentConversionException(index, e);
			}
		}
		public T GetObject<T>(int index)
		{
			try
			{
				return (T)_list[index];
			}
			catch (Exception e)
			{
				throw new ArgumentConversionException(index, e);
			}
		}
	}
}
